const DynamicProgramming = require("../template")

function testSequenceProblems() {
  const dp = new DynamicProgramming()

  console.log(
    "1. 最长公共子序列基础测试:",
    (() => {
      return dp.longestCommonSubsequence("abcde", "ace") === 3 &&
             dp.longestCommonSubsequence("abc", "abc") === 3 &&
             dp.longestCommonSubsequence("abc", "def") === 0
    })()
  )

  console.log(
    "2. 最长公共子序列复杂测试:",
    (() => {
      return dp.longestCommonSubsequence("bsbininm", "jmjkbkjkv") === 1 &&
             dp.longestCommonSubsequence("pmjghexybyrgzczy", "hafcdqbgncrcbihkd") === 4
    })()
  )

  console.log(
    "3. 最长递增子序列基础测试:",
    (() => {
      return dp.longestIncreasingSubsequence([10, 9, 2, 5, 3, 7, 101, 18]) === 4 &&
             dp.longestIncreasingSubsequence([0, 1, 0, 3, 2, 3]) === 4 &&
             dp.longestIncreasingSubsequence([7, 7, 7, 7, 7, 7, 7]) === 1
    })()
  )

  console.log(
    "4. 最长递增子序列复杂测试:",
    (() => {
      return dp.longestIncreasingSubsequence([1, 3, 6, 7, 9, 4, 10, 5, 6]) === 6 &&
             dp.longestIncreasingSubsequence([1, 2, 3, 4, 5]) === 5
    })()
  )

  console.log(
    "5. 编辑距离基础测试:",
    (() => {
      return dp.editDistance("horse", "ros") === 3 &&
             dp.editDistance("intention", "execution") === 5 &&
             dp.editDistance("abc", "abc") === 0
    })()
  )

  console.log(
    "6. 编辑距离边界测试:",
    (() => {
      return dp.editDistance("", "abc") === 3 &&
             dp.editDistance("abc", "") === 3 &&
             dp.editDistance("", "") === 0
    })()
  )

  console.log(
    "7. 最长回文子序列基础测试:",
    (() => {
      return dp.longestPalindromeSubseq("bbbab") === 4 &&
             dp.longestPalindromeSubseq("cbbd") === 2 &&
             dp.longestPalindromeSubseq("a") === 1
    })()
  )

  console.log(
    "8. 最长回文子序列复杂测试:",
    (() => {
      return dp.longestPalindromeSubseq("abc") === 1 &&
             dp.longestPalindromeSubseq("racecar") === 7
    })()
  )

  console.log(
    "9. 空字符串边界测试:",
    (() => {
      return dp.longestCommonSubsequence("", "abc") === 0 &&
             dp.longestIncreasingSubsequence([]) === 0 &&
             dp.editDistance("", "") === 0 &&
             dp.longestPalindromeSubseq("") === 0
    })()
  )

  console.log(
    "10. 单字符边界测试:",
    (() => {
      return dp.longestCommonSubsequence("a", "a") === 1 &&
             dp.longestIncreasingSubsequence([1]) === 1 &&
             dp.editDistance("a", "b") === 1 &&
             dp.longestPalindromeSubseq("a") === 1
    })()
  )

  console.log(
    "11. this上下文序列测试:",
    (() => {
      const seqObj = {
        multiplier: 2,
        processSequence: function(text1, text2) {
          const dp = new DynamicProgramming()
          const result = dp.longestCommonSubsequence(text1, text2)
          return result * this.multiplier
        }
      }
      return seqObj.processSequence("abc", "ac") === 4 // 2 * 2 = 4
    })()
  )

  console.log(
    "12. 复杂对象this绑定测试:",
    (() => {
      const seqConfigObj = {
        config: { offset: 5 },
        processWithConfig: function(arr) {
          const dp = new DynamicProgramming()
          const result = dp.longestIncreasingSubsequence(arr)
          return result + this.config.offset
        }
      }
      return seqConfigObj.processWithConfig([1, 2, 3]) === 8 // 3 + 5 = 8
    })()
  )
}

testSequenceProblems()
